<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>LcsdAdmin</title>
    <link rel="stylesheet" href="{{URL::asset('/layui/css/layui.css')}}">
</head>
<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin">
        <!-- 顶部区域 -->
        @include('admin.common.header')
        <!-- 垂直导航菜单区域 -->
        @include('admin.common.left')
        <!-- 内容主体区域 -->
        <div class="layui-body" style="padding: 10px" lay-filter="demo">
            <!-- 按钮区域 -->
{{--            <div class="layui-btn-group">--}}
{{--                <a type="button" class="layui-btn layui-btn-sm add">--}}
{{--                    <i class="layui-icon"></i>--}}
{{--                </a>--}}
{{--                --}}{{--<a type="button" class="layui-btn layui-btn-sm" href="{{url('adminuser/edit')}}">--}}
{{--                    --}}{{--<i class="layui-icon"></i>--}}
{{--                --}}{{--</a>--}}
{{--                <a type="button" class="layui-btn layui-btn-sm"  href="https://www.baidu.com">--}}
{{--                    <i class="layui-icon"></i>--}}
{{--                </a>--}}
{{--            </div>--}}
            <!-- 列表区域 -->
            <table class="layui-table" lay-data="{width: 675, height:675, url:'/admin/adminuser/getInfo', page:true, id:'idTest'}" lay-filter="demo">
                <thead>
                <tr>
                    <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
                    <!-- <th lay-data="{field:'id', width:80, sort: true, fixed: true}">ID</th> -->
                    <th lay-data="{field:'nickname', width:150}">昵称</th>
                    <th lay-data="{field:'username', width:150}">用户名</th>
                    <th lay-data="{field:'addtime' , width:150,templet:function(d){ return  layui.util.toDateString(d.addtime*1000,'yyyy-MM-dd')}}">注册时间</th>
                    <th lay-data="{fixed: 'right', width:180, align:'center', toolbar: '#barDemo'}">操作</th>
                </tr>
                </thead>
            </table>

            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
{{--                <a class="layui-btn layui-btn-xs" lay-event="edit" >编辑</a>--}}
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
        </div>
        <!-- 底部主体区域 -->
        @include('admin.common.footer')
    </div>
    <script src="{{URL::asset('/layui/layui.js')}}"></script>
    <script>
        //动态更新左侧导航下拉效果
        layui.use('element', function(){
            var element = layui.element;
        });

        //JavaScript代码区域
        layui.use('table', function(){
            var table = layui.table;
            //监听表格复选框选择
            table.on('checkbox(demo)', function(obj){
                console.log(obj)
            });
            //监听工具条
            table.on('tool(demo)', function(obj){
                var data = obj.data;
                if(obj.event === 'detail'){
                    layer.msg('你真的看不见 “ '+ data.name + ' ” 么？');
                } else if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        obj.del();
                        layer.close(index);
                    });
                } else if(obj.event === 'edit'){
                    //layer.alert('编辑行：<br>'+ JSON.stringify(data))
                    layer.open({
                        type: 2,
                        area: ['700px', '450px'],
                        fixed: false, //不固定
                        maxmin: true,
                        content: "{{url('admin/adminuser/edit')}}",
                        success: function (layero, index) {
                            // 获取子页面的iframe
                            var iframe = window['layui-layer-iframe' + index];
                            // 向子页面的全局函数child传参
                            iframe.child(JSON.stringify(data));
                        }
                    });
                }
            });

            var $ = layui.$, active = {
                getCheckData: function(){ //获取选中数据
                    var checkStatus = table.checkStatus('idTest')
                        ,data = checkStatus.data;
                    layer.alert(JSON.stringify(data));

                }
                ,getCheckLength: function(){ //获取选中数目
                    var checkStatus = table.checkStatus('idTest')
                        ,data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                }
                ,isAll: function(){ //验证是否全选
                    var checkStatus = table.checkStatus('idTest');
                    layer.msg(checkStatus.isAll ? '全选': '未全选')
                }
            };

            $('.demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            $('.add').on('click', function(){
                layer.open({
                    type: 2,
                    area: ['700px', '450px'],
                    fixed: false, //不固定
                    maxmin: true,
                    content: "{{url('admin/user/add')}}",
                    success: function (layero, index) {
                        // 获取子页面的iframe
                        var iframe = window['layui-layer-iframe' + index];
                    }
                });
            })

        });
    </script>
</body>
</html>
